package algorithm;

import calculators.DiffusionCalculator;
import calculators.ForagingCalculator;
import calculators.MotionCalculator;
import herd.Food;
import herd.Krill;
import herd.Randomizer;

import java.util.List;

public class KHAlgorithm {
    private DiffusionCalculator diffusionCalculator = new DiffusionCalculator();
    private ForagingCalculator foragingCalculator = new ForagingCalculator();
    private MotionCalculator motionCalculator = new MotionCalculator();
    private List<Krill> herd;
    private Food food;
    private AlgorithmParameters algorithmParameters = new AlgorithmParameters();

    public static void main(String[] args) {
        KHAlgorithm algorithm = new KHAlgorithm();
        algorithm.simulate();
    }

    public void simulate() {
        init();
        while (algorithmParameters.nextIteration()) {
            fitnessEvaluation();
            motionCalculation();
            geneticOperators();
            updateKrillPositions();
        }

    }

    private void init() {
        Randomizer randomizer = new Randomizer();
        herd = randomizer.randomizeHerd(algorithmParameters);
        food = randomizer.randomizeFood();
    }

    private void fitnessEvaluation() {
        //don't know how yet
    }

    private void motionCalculation() {
        motionCalculator.calculateMotion(herd, algorithmParameters);
        foragingCalculator.calculateForagingMotion(herd, algorithmParameters,food);
        diffusionCalculator.calculateDiffusionMotion(herd,algorithmParameters);
    }

    private void geneticOperators() {
        //not supported
    }

    private void updateKrillPositions() {
      for (Krill krill: herd){
          krill.updatePosition();
      }
    }
}
